// pages/PlaceOrder/PlaceOrder.js
import {axios} from "../../api/http.js"
import {addOrderForm} from "../../api/Url"
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  bindGotoAddress(){
    wx.navigateTo({
      url: '../address/address',
    })
  },
  data: {
    nbTitle: '商品订单',
    OrderList:[],
    Sum:"",
    orderTitle:app.globalData.orderTitle
  },
  addOrderList(){
    console.log(app.globalData.orderList)
    var params = {
      orderFormDetails:[],
      orderNumber:new Date().getTime(),
      //订单状态
      orderStatus:"0",
      //下单时间
      orderTime:new Date().getTime(),
      //购物用户
      orderUser:app.globalData.openId
    }
    for(var i=0;i<app.globalData.orderList.length;i++){
        params.orderFormDetails = [...params.orderFormDetails,app.globalData.orderList[i].orderFormDetails]
    }
    axios(addOrderForm,{params:params},"post",(res)=>{
      console.log(res)
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(app.globalData.orderList)
    this.setData({
      OrderList:app.globalData.orderList,
      Sum:options.Sum
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    app.globalData.orderList = []
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})